/**
 * 历史对账管理初始化
 */
var BillCheck = {
    id: "BillCheckTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
BillCheck.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '核对编号', field: 'billCheckNum', visible: true, align: 'center', valign: 'middle'},
            {title: '开始时间', field: 'beginTime', visible: true, align: 'center', valign: 'middle'},
            {title: '结束时间', field: 'endTime', visible: true, align: 'center', valign: 'middle'},
            {title: '交易对象', field: 'traner', visible: true, align: 'center', valign: 'middle'},
            {title: '收银单据数-对应t_bill表的条数', field: 'billCount', visible: true, align: 'center', valign: 'middle'},
            {title: '总金额', field: 'moneyAll', visible: true, align: 'center', valign: 'middle'},
            {title: '转接金额-做转结的负账', field: 'moneyNotPay', visible: true, align: 'center', valign: 'middle'},
            {title: '现金', field: 'cash', visible: true, align: 'center', valign: 'middle'},
            {title: '微信', field: 'weixin', visible: true, align: 'center', valign: 'middle'},
            {title: '支付宝', field: 'alipay', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'bank', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
            {title: '操作人', field: 'editUser', visible: true, align: 'center', valign: 'middle'},
            {title: '网点ID', field: 'dotId', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
BillCheck.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        BillCheck.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加历史对账
 */
BillCheck.openAddBillCheck = function () {
    var index = layer.open({
        type: 2,
        title: '添加历史对账',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/billCheck/billCheck_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看历史对账详情
 */
BillCheck.openBillCheckDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '历史对账详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/billCheck/billCheck_update/' + BillCheck.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除历史对账
 */
BillCheck.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/billCheck/delete", function (data) {
            Feng.success("删除成功!");
            BillCheck.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("billCheckId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询历史对账列表
 */
BillCheck.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    BillCheck.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = BillCheck.initColumn();
    var table = new BSTable(BillCheck.id, "/billCheck/list", defaultColunms);
    table.setPaginationType("client");
    BillCheck.table = table.init();
});
